import 'package:flutter/material.dart';
import 'package:xiongan_app_yy/common/user_singleton.dart';
import 'package:xiongan_app_yy/net/internet.dart';
import 'package:xiongan_app_yy/utils/toast_utils.dart';

//
class LibBackProvider extends ChangeNotifier {
  // _netStatus系列表示请求状态：
  // false未请求
  // true请求中

  bool _netStatus1 = false;
  List _listData = List(); //列表数据
  bool _down;
  bool _up;

  bool _netStatus2 = false;
  List _detailListData = List(); //详情列表数据

  Map<String, dynamic> _detailData = Map(); //详情数据

  //getter方法获取数据
  get netStatus1 => _netStatus1;

  get listData => _listData;

  get down => _down;

  get netStatus2 => _netStatus2;

  get detailListData => _detailListData;

  get detailData => _detailData;

  //列表查询
  void getList({Map<String, dynamic> sendObj}) async {
    sendObj["warehouseid"] = DataSingleton().warehouseChoice.id;
    _netStatus1 = true;
    _listData = [];
    notifyListeners();
    // print(DataSingleton().warehouseChoice.id);
    Map<String, dynamic> res = await Internet().get(
        "WTesting/DescSpotcheckTask/GetAllDescSpotcheckGobackTask",
        params: sendObj);
    if (res['flag'] == "success") {
      _listData = res['datas'];
    }else{
      TostUtil.showToast(res['msg']);
    }
    _netStatus1 = false;
    notifyListeners();
  }

  //详情列表查询
  void getDetailListData({@required String orderid}) async {
    Map<String, dynamic> sendObj = {"orderid": orderid};
    //初始化数据和加载状态
    _netStatus2 = true;
    _detailListData = [];
    notifyListeners();
    Map<String, dynamic> res = await Internet().get(
        "WTesting/DescSpotcheckTaskDetail/GetAllDescSpotcheckTaskDetail",
        params: sendObj);
    if (res['flag'] == "success") {
      _detailListData = res['datas'];
    } else {
      TostUtil.showToast(res['msg']);
    }
    _netStatus2 = false;
    notifyListeners();
  }

//回库
  Future<dynamic> sendLibBackTask({Map<String, dynamic> sendObj}) async {
    Map<String, dynamic> res = await Internet().post(
        "WTesting/DescSpotcheckTaskDetail/SendSpotcheckGobackTaskPutawayMaterial",
        params: sendObj);
    if (res['flag'] == "success") {
      TostUtil.showToast("回库成功");
    } else {
      TostUtil.showToast(res['msg']);
    }
    return res['datas'];
  }
}
